package cn.tjie.sys.controller;

import cn.tjie.basic.util.AjaxResult;
import cn.tjie.basic.util.PageList;
import cn.tjie.sys.domain.SystemdictionaryType;
import cn.tjie.sys.query.SystemdictionaryDetailQuery;
import cn.tjie.sys.service.SystemdictionaryTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口类：部门
 */
@RestController //@Controller +@ResponseBody
@RequestMapping("/systemdictionaryType")
@Api(value ="部门接口类" ,description ="处理部门CRUD操作的")
public class SystemdictionaryTypeController {

    //自动注入
    @Autowired
    private SystemdictionaryTypeService systemdictionarytypeService;

    /**
     * 接口：查询单个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "接口：查询单个对象")
    public SystemdictionaryType findOne(@PathVariable("id")Long id){
        return systemdictionarytypeService.loadById(id);
    }

    /**
     * 接口：查询所有
     * @return
     */
    @GetMapping
    @ApiOperation(value = "接口：查询所有对象")
    public List<SystemdictionaryType> findAll(){
        return systemdictionarytypeService.loadAll();
    }

    /**
     * 接口：删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "接口：删除单个对象")
    public AjaxResult del(@PathVariable("id")Long id){
        try {
            systemdictionarytypeService.del(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }

    }

    /**
     * 接口：添加和修改
     * @param systemdictionarytype
     * @return
     */
    @PutMapping
    @ApiOperation(value = "接口：添加和修改单个对象")
    public AjaxResult addAndUpdate(@RequestBody SystemdictionaryType systemdictionarytype){
        try {
            if(systemdictionarytype.getId()==null){
                //没有获取到id 表示为添加
                systemdictionarytypeService.save(systemdictionarytype);
            }else {
                //有id为修改
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    /**
     * 接口：分页和高级查询
     * @param systemdictionarytypeQuery
     * @return
     */
    @PostMapping
    @ApiOperation(value = "接口：分页和高级查询")
    public PageList<SystemdictionaryType> pageQuery(@RequestBody SystemdictionaryDetailQuery systemdictionarytypeQuery){
        return systemdictionarytypeService.pageQuery(systemdictionarytypeQuery);
    }


    @PatchMapping
    @ApiOperation(value = "接口：批量删除")
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.patchDelete(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }

    }

    /**
     * 接口：获取部门数
    // * @return
    // */
    //@GetMapping("/deptTree")
    //@ApiOperation(value = "接口：获取部门数")
    //public List<Systemdictionarytype> deptTree(){
    //    return systemdictionarytypeService.deptTree();
    //}

}
